package com.example.retrofit.controller;

import com.example.retrofit.api.GitHubApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;

/**
 * @author fans
 */
@Slf4j
@RestController
public class GithubController {

    @Autowired
    private GitHubApi gitHubApi;

    @GetMapping("/github/repos/{user}")
    public String repos(@PathVariable String user) throws IOException {
        Call<String> result = gitHubApi.listRepos(user);
        Response<String> response = result.execute();
        log.info(response.toString());
        return response.body();
    }

}
